package com.xiaoluo.lottery.algo;

import java.util.Calendar;

/**
 * Created by issac on 16/4/6.
 */
public class AlgoUtil {
    /**
     * @param ts 时间，ms
     * @param n  ts之后的第几个整分钟
     * @return ts之后的第n个整分钟
     */
    public static long getNextMinutes(long ts,int n) {
        Calendar c = Calendar.getInstance();
        c.setTimeInMillis(ts);
        c.set(Calendar.SECOND, 0);
        c.set(Calendar.MILLISECOND, 0);
        c.add(Calendar.MINUTE,n);
        return c.getTimeInMillis();
    }


    public static long getNextXMinutes(long ts,int n,int gap) {
        Calendar c = Calendar.getInstance();
        c.setTimeInMillis(ts);
        c.set(Calendar.SECOND, 0);
        c.set(Calendar.MILLISECOND, 0);
        int minute = c.get(Calendar.MINUTE);
        c.add(Calendar.MINUTE, gap * n - minute % gap);
        return c.getTimeInMillis();
    }

    public static String join(String[] strs) {
        if (strs == null) {
            return "";
        }
        StringBuilder sb = new StringBuilder();
        for (String s : strs) {
            sb.append(s);
        }
        return sb.toString();
    }


}
